/* 
* SIP XML Scenario Maker
* Copyright 2008 Rachid El Khayari
*
* This file is part of SIP XML Scenario Maker (SXSM).
*
* SXSM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SXSM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SXSM.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
#include <QMainWindow>
#include <QSplashScreen>
#include <QSettings>
#include <QString>
#include <QtNetwork>

#include "mainwindow.h"
#include "sxsm.h"


int main(int argc, char *argv[])
{
	// create instance of QApplicaction and attach input parameters
	// QApplication manages the GUI application's control flow and main settings
	QApplication app(argc, argv);

	/* create default settings at first run of application
	In Windows systems e.g. these settings are saved in the registry */
	QSettings mysettings("RashSoft","sxsm");
	if(mysettings.value("firstRun").toInt()!=1){
		mysettings.setValue("SIPp Path","data/sipp/sipp");
		mysettings.setValue("datadir","data/");
		mysettings.setValue("messagedir","data/messages/");
		mysettings.setValue("scenariodir","data/scenarios/");
		mysettings.setValue("csvdir","data/csvs/");
		mysettings.setValue("logdir","data/logs/");
		mysettings.setValue("firstRun","1");
	}
	QString splashpath = mysettings.value("datadir").toString();
	splashpath.append("splash.JPG");
	// create splashscreen (maybe needed if application's startup time is to long)
	QPixmap pixmap(splashpath);
	QSplashScreen splash(pixmap);
	splash.show();
	app.processEvents();
	
	// create instance of QMainWindow that provides a main application window
	MainWindow mainWin;
	
	// create instance of XMLScenarioMaker
	sxsm maker;

	// make the splash screen wait until the widget mainWin is 
	// displayed before calling close() on itself
	splash.finish(&mainWin);

	// set XMLScenarioMaker as central widget
	mainWin.setCentralWidget(&maker);

	// Window title of main window is set
	mainWin.setWindowTitle("SIP XML Scnenario Maker - SXSM");

	/* show mainWin maximized (affects only Windows systems, no effect on X11)
	comment the following line and uncomment the next 2 ones if you
	don't want the application ever to start maximized */
	mainWin.showMaximized();
	//mainWin.resize(800,600);
	//mainWin.show();
	
	/* main() passes control to Qt. QCoreApplication::exec() will return when the application exits.
	In QCoreApplication::exec(), Qt receives and processes user and system events and passes these on
	to the appropriate widgets.*/
	return app.exec();
}
